#ifndef __SOCKET_SERVER_H__
#define __SOCKET_SERVER_H__

#include "SocketBase.h"
#include "format.h"

#define sSocketServer SocketServer::GetInstance()
class SocketServer : public SocketBase
{
public:
	static SocketServer* create();
	static SocketServer* GetInstance();
	SocketServer();
	~SocketServer();
	bool startServer();
	void sendMessage(HSocket socket, WorldPacket data, int count);
	void sendMessage(WorldPacket data, int count);
	std::function<void(const char* ip)> onStart;
	std::function<void(HSocket socket)> onNewConnection;
	std::function<void(const char* data, int count)> onRecv;
	std::function<void(HSocket socket)> onDisconnect;
	void MessageRecv(std::string abc, HSocket _HSocket);
private:
	bool initServer();
	void acceptClient();
	void acceptFunc();
	void newClientConnected(HSocket socket);
	void recvMessage(HSocket socket);
private:
	HSocket _socketServer;
private:
	std::list<HSocket> _clientSockets;
};

#endif